package com.blog.web.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.blog.common.domain.dto.FriendLinkDto;
import com.blog.common.domain.entity.FriendLink;
import com.blog.common.domain.vo.FriendLinkVo;
import com.blog.common.mapper.dao.FriendLinkMapper;
import com.blog.web.service.FriendLinkService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 友链列表 服务实现类
 * </p>
 *
 * @author Valerie
 * @since 2023-02-18
 */
@Service
public class FriendLinkServiceImpl extends ServiceImpl<FriendLinkMapper, FriendLink> implements FriendLinkService {


    @Override
    public List<FriendLinkVo> listFriendLinks() {
        return BeanUtil.copyToList(this.list(null), FriendLinkVo.class);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void saveFriendLink(FriendLinkDto friendLinkDto) {
        FriendLink friendLink = BeanUtil.copyProperties(friendLinkDto, FriendLink.class);
        this.save(friendLink);
    }
}
